package com.glorysoft.hlgdpda.ui.trackin.view

import android.os.Bundle
import androidx.databinding.ViewDataBinding
import com.glorysoft.hlgdpda.BR
import com.glorysoft.hlgdpda.R
import com.glorysoft.hlgdpda.base.BaseActivity
import com.glorysoft.hlgdpda.databinding.ActivityBatchSizeTrackInBinding
import com.glorysoft.hlgdpda.entity.ui.ToastMessageBean
import com.glorysoft.hlgdpda.ui.trackin.viewmodel.BatchSizeTrackInViewModel
import kotlinx.android.synthetic.main.activity_batch_size_track_in.*

/**
 * FileName: BatchSizeTrackInActivity
 * Author: XJH
 * Date: 2021/10/11 11:42
 * Description:
 * History:
 */
class BatchSizeTrackInActivity : BaseActivity<BatchSizeTrackInViewModel,ActivityBatchSizeTrackInBinding>() {
    override fun layoutId(): Int {
        return R.layout.activity_batch_size_track_in
    }

    override fun initVariableId(): Int {
        return BR.batchSizeTrackInViewModel
    }

    override fun initView(savedInstanceState: Bundle?) {
        setTitle("批量进站")
        setRightListener("提交") {
            if (viewModel.carrierUpItems.isEmpty()){
                viewModel.defUI.toastEvent.value = ToastMessageBean("请先添加批次，再进行操作",false)
                return@setRightListener
            }

            viewModel.trackIn(etEqpWorkID.text.toString())
        }

        initEdit(etLot,object : EditTextListener{
            override fun onTextChangeListener(s: String) {
                viewModel.searchLotInfo(s,etEqpWorkID.text.toString())

            }

        })

        initEdit(etCarrierUp,object : EditTextListener{
            override fun onTextChangeListener(s: String) {
                viewModel.searchCarrierInfo(s)
            }
        })
    }

    override fun initData() {
        rvUpMaterialList.setEmptyView(upMaterialEmptyView)
        viewModel.defUI.callObserve.observe(this){
            when(it.type){
                100 ->{
                    etLot.setText("")
                    etCarrierUp.setText("")
                }
                200 ->{
                    tvNumber.text = it.item.toString()
                }
            }

        }

        viewModel.defUI.startActivity.observe(this){
            etLot.setText("")
            etCarrierUp.setText("")
            etEqpWorkID.setText("")
        }
    }
}